package com.netease.financial.base.customerservice;

import static com.netease.financial.base.web.WebStoragePreferencesHelper.KEY_LOCAL_STORAGE_USER_ID;

import com.netease.financial.R;
import com.netease.financial.base.web.WebStoragePreferencesHelper;
import com.netease.financial.common.util.NfsLog;
import com.netease.financial.common.util.preferences.PreferencesHelper;

/**
 * Created by wyf on 10/10/15.
 */
class CustomerServicePreferencesHelper {

    private static final String TAG = CustomerServicePreferencesHelper.class.getSimpleName();

    private static final String PREFERENCES_FILE_NAME = PreferencesHelper.getFullPreferenceFileName("customer_service");

    private static final String KEY_WEB_URL = "web_url";
    private static final String KEY_WEB_TITLE = "web_title";
    private static final String KEY_CHAT_SCREEN_TITLE = "chat_screen_title";
    private static final String KEY_USER_ID = "userId";

    private static String sDefaultChatScreenTitle;
    private static PreferencesHelper sPreferencesHelper;

    public static PreferencesHelper getPreferencesHelper() {
        if (sPreferencesHelper == null) {
            sDefaultChatScreenTitle = PreferencesHelper.getContext().getString(R.string.app_name);
            sPreferencesHelper = PreferencesHelper.newInstance(PREFERENCES_FILE_NAME);
        }
        return sPreferencesHelper;
    }

    public static void saveWebUrl(String url) {
        getPreferencesHelper().putString(KEY_WEB_URL, url);
    }

    public static String getWebUrl() {
        return getPreferencesHelper().getString(KEY_WEB_TITLE, "");
    }

    public static void removeWebUrl() {
        getPreferencesHelper().remove(KEY_WEB_URL);
    }

    public static void saveWebTitle(String title) {
        getPreferencesHelper().putString(KEY_WEB_TITLE, title);
    }

    public static String getWebTitle() {
        return getPreferencesHelper().getString(KEY_WEB_TITLE, "");
    }

    public static void removeWebTitle() {
        getPreferencesHelper().remove(KEY_WEB_TITLE);
    }

    public static void saveUserId(String userId) {
        NfsLog.d(TAG, "saveUserId:" + userId);
        getPreferencesHelper().putString(KEY_USER_ID, userId);
    }

    public static String getUserId() {
        return getPreferencesHelper().getString(KEY_USER_ID, "");
    }

    public static String getChatScreenTitle() {
        return getPreferencesHelper().getString(KEY_CHAT_SCREEN_TITLE, sDefaultChatScreenTitle);
    }

}
